import axios from "axios";
const state = {
    goodsTypeList:[],
    goodsListByTypeId:[],
    goodsList:[]
};
const mutations={
    CHANGE_GOODS_TYPE_LIST(state,goodsTypeList){
        state.goodsTypeList = goodsTypeList
    },
    CHANGE_GOODS_LIST_BYID(state,goodsTypeList){
        state.goodsListByTypeId = goodsTypeList
    },
    CHANE_GOODS_LIST(state,goodsList){
        // console.log(goodsList)
        state.goodsList = goodsList
    }
};
const actions = {
    async getGoodsList({commit},query={}){
        const {pageIndex=1} = query;
      const data = await axios.get("/goodsList",{
          params:{
              pageIndex
          }
      })
    //   console.log(data)
        commit("CHANE_GOODS_LIST",data.goodsList)
    },
    async getGoodsListByTypeId({commit},shopId){
        const data = await axios.get("/goodsListByTypeId/"+shopId);
        // console.log(data)
        commit("CHANGE_GOODS_LIST_BYID",data.goodsTypeList)
    },
    async addGoodsTypeList({},params){
        // console.log(params)
        const data = await axios.post("/goodsTypeList",params)
        // console.log(data);
        // return data

    },
    async getGoodsTypeList({commit},query={}){
        const {pageIndex=1} = query;
        const data = await axios.get("/goodsTypeList",{
            params:{
                pageIndex
            }
        })
        // console.log(data)
        commit("CHANGE_GOODS_TYPE_LIST",data.goodsTypeList)

    }
}
export default {
    state,
    mutations,
    actions
}